package com.bigdata.bookinfo.mapper;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class CommentDisMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

    static int i = 0;

    @Override
    protected void map(LongWritable key, Text value, Context context) throws InterruptedException, IOException {
        String[] line = value.toString().split("\t");
        String comment = line[1];
        double l = -1;
        try {
            l = Double.parseDouble(comment);
        } catch (Exception e) {
            return;
        }
        if (l<0){
            return;
        }
        if (l<=10000.0){
            context.write(new Text("0~10000"),new IntWritable(1));
        } else if (l <= 25000.0) {
            context.write(new Text("10000~25000"),new IntWritable(1));
        } else if (l<=50000.0) {
            context.write(new Text("25000~50000"),new IntWritable(1));
        }else if (l<=100000.0){
            context.write(new Text("50000~100000"),new IntWritable(1));
        }
        else if (l<=200000.0){
            context.write(new Text("100000~200000"),new IntWritable(1));
        }
        else {
            context.write(new Text("200000以上"),new IntWritable(1));
        }
    }
}
